﻿Imports System
Imports System.Runtime.Remoting.Messaging
Imports System.Runtime.Serialization
Imports System.Security.Permissions

Namespace System.Workflow.Activities
    <Serializable> _
    Friend NotInheritable Class IdentityContextData
        Implements ILogicalThreadAffinative, ISerializable
        ' Methods
        Friend Sub New(ByVal identity As String)
            Me.identity = identity
        End Sub

        Private Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
            Dim enumerator As SerializationInfoEnumerator = info.GetEnumerator
            Do While enumerator.MoveNext
                If enumerator.Name.Equals("identity") Then
                    Me.identity = CStr(enumerator.Value)
                End If
            Loop
        End Sub

        <SecurityPermission(SecurityAction.Demand, SerializationFormatter:=True)> _
        Private Sub System.Runtime.Serialization.ISerializable.GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext) Implements ISerializable.GetObjectData
            If (Not Me.identity Is Nothing) Then
                info.AddValue("identity", Me.identity.ToString)
            End If
        End Sub


        ' Properties
        Friend ReadOnly Property Identity As String
            Get
                Return Me.identity
            End Get
        End Property


        ' Fields
        Private identity As String
        Friend Const IdentityContext As String = "__identitycontext__"
    End Class
End Namespace

